As one type of nonvolatile semiconductor memory device, a NAND flash memory is known. In the NAND flash memory, data is written in units called page. In case of writing data in the NAND flash memory, it is difficult to accurately write the data into all memory cells by a single write operation. Therefore, in a write sequence in the NAND flash memory, a write stage constituted of three steps, i.e., (1) writing, (2) verifying, and (3) searching and counting memory cells (fail bits) in which writing is not finished is repeated.
Further, there is also known a system that allows fail bits and finishes a write sequence if the number of the fail bits is not greater than a predetermined allowable bit number. Adopting this system enables increasing a data write speed. To use this system, a circuit that counts the number of fail bits is required.